--[[
    聊天表情列表弹出
]]--

local blaze = require "blaze"
local app = require "app"
local game = app.game.running

local Emoji = require "club.threecard.gamelib.UI.Chat.Emoji"

local Item = game.ui.element()

function Item:ctor(config)
    self.config = config
    self.res = "club.threecard.gamelib/ui/chat.b:EmojiListItem"
    self.emoji = Emoji.new(config)
end

function Item:on_load()
    self:super("on_load")
    self.emoji:load()
end

function Item:on_injected(bind)
    bind("button.click", self.btn, self.on_click)
    self.emoji:set_parent(self.root)
end

function Item:on_click()
end

function Item:on_release()
    self:super("on_release")
    self.emoji:release()
end


local M = game.ui.element()

function M:ctor()
    local SimpleList = require "blaze.ui.widget.SimpleList"
    self.list = SimpleList.new()
    self.list.create_item = function(_, data, index)
        local ret = Item.new(data)
        ret.on_click = function() self:on_item_click(ret) end
        return ret
    end
end

function M:on_set_gameobject()
    self:super("on_set_gameobject")
    self.loaded = true
end

function M:on_injected(bind)
    self.list:set_parent(self.content_root)
    self.list:fill(game.config.chat.emojis)
end

function M:on_item_click(item)
    game.event.emit("发送聊天表情")
    game.store.chat.say_emoji(tostring(item.config.id))
end

function M:on_release()
    self:super("on_release")
    self.list:release()
end

return M